package com.tesis_2.Utils;

import java.util.ArrayList;

import org.json.JSONException;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.t2_clientback.R;
import com.tesis_2.BL.BLRestaurants;
import com.tesis_2.MO.MOPlato;
import com.tesis_2.MO.MORestaurant;

public class UTPLatosAdapter extends ArrayAdapter<MOPlato> {
		
	private final Context context;
	private final ArrayList<MOPlato> values;
	private ArrayList<MORestaurant> lsrest;
	
	public UTPLatosAdapter(Context context, ArrayList<MOPlato> objects) throws JSONException {
		super(context, R.layout.activity_uiplatos, objects);
		this.context = context;
		this.values = objects;
		BLRestaurants.fillRestaurants();
		lsrest = BLRestaurants.getLsRest();
		// TODO Auto-generated constructor stub
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
			.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 
		View rowView = inflater.inflate(R.layout.activity_uiplatos, parent, false);
		((TextView) rowView.findViewById(R.id.txtPlato_platos)).setText( ((MOPlato) getItem(position)).getName());
		((TextView) rowView.findViewById(R.id.txtRestaurante_platos)).setText( findRestaurantById(((MOPlato) getItem(position)).getRestaurant_id()).getName());
		
		((TextView) rowView.findViewById(R.id.txtDescr_platos)).setText( ((MOPlato) getItem(position)).getDescr());
		
		
		return rowView;
	}
	
	public MORestaurant findRestaurantById(Integer Restid)
	{
		
		for(MORestaurant r : lsrest)
		{
			if (r.getId() == Restid) return r;
		}
		
		return null;
	}

}
